<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Controller\AdminbaseController;

/**
 * 文件控制器
 * 主要用于下载模型的文件上传和下载
 */
class FileController extends AdminbaseController {

    /* 文件上传 */
    public function upload(){
		$return  = array('status' => 1, 'info' => '上传成功', 'data' => '');
	
		/* 调用文件上传组件上传文件 */
		$File = D('File');
		
		if(I('get.action')=="file"){
			$file_driver = C('DOWNLOAD_UPLOAD_DRIVER');
			$file_config=C('DOWNLOAD_UPLOAD');
			
		}
		else{
			$file_driver = C('PICTURE_UPLOAD_DRIVER');
			$file_config=C('PICTURE_UPLOAD');
			
		}
		
		
		
		$info = $File->upload(
			$_FILES,
				I('get.'),
			$file_config,
			$file_driver,
			C("UPLOAD_{$file_driver}_CONFIG")
		);

        /* 记录附件信息 */
        if($info){
          //  $return['data'] = think_encrypt(json_encode($info['download']));
         $return['status'] = 1;
            $return = array_merge($info['download'], $return);
            
            
        } else {
            $return['status'] = 0;
            $return['info']   = $File->getError();
        }

        /* 返回JSON数据 */
        $this->ajaxReturn($return);
    }

    /* 下载文件 */
    public function download($id = null){
        if(empty($id) || !is_numeric($id)){
            $this->error('参数错误！');
        }

        $logic = D('Download', 'Logic');
        if(!$logic->download($id)){
            $this->error($logic->getError());
        }

    }



    public function  del_file(){


         $att=I("get.att");
        if(!$att){
            $this->error("缺少参数！");
        }

    	if (D('File')->del_file($att)!==false) {
    		$this->success("删除成功");
    	} else {
    		$this->error("删除失败！");
    	}




    }

    public  function  del(){

        $id=I("get.id");
        if(!$id){
            $this->error("缺少参数！");
        }

        if (D('File')->del($id)!==false) {
            $this->success("删除成功1");
        } else {
            $this->error("删除失败！");
        }


    }

    //排序
    public function listorders() {
        $status = parent::_listorders(D('File'));
        if ($status) {
            $this->success("排序更新成功！");
        } else {
            $this->error("排序更新失败！");
        }
    }

    
    public function run() {
    	 
    	$data = new \Org\Util\Ueditor();
    	echo $data->output();
    }
    
    
}
